package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 套餐控制层
 *
 * @Author mr.li
 * @Date 2025/7/8 21:18
 */
@Api(tags = "套餐相关接口")
@Slf4j
@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;


    /**
     * 新增套餐
     * @param setmealDTO 套餐信息
     * @return
     */
    @PostMapping
    @ApiOperation("新增套餐")
    public Result<String> save(@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐：{}", setmealDTO);
        setmealService.save(setmealDTO);
        return Result.success();
    }

    /**
     * 套餐分页查询
     * @param setmealPageQueryDTO   分页请求参数
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("套餐分页查询：{}", setmealPageQueryDTO);
        PageResult pageResult=setmealService.pageQuery(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除套餐
     * @param ids   要删除的套餐id集合
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除套餐")
    public Result<String> deleteByIds(@RequestParam("ids") List<Integer> ids){
        log.info("删除套餐：{}", ids);
        setmealService.deleteByIds(ids);
        return Result.success();

    }




    /**
     * 根据id查询套餐
     * @param setmealId   套餐id
     * @return
     */
    @GetMapping("/{setmealId}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getById(@PathVariable Integer setmealId){
        log.info("根据id查询套餐：{}", setmealId);
        SetmealVO setmealVO =setmealService.getById(setmealId);
        return Result.success(setmealVO);
    }

    /**
     * 修改套餐信息
     * @param setmealDTO   修改后的套餐信息
     * @return
     */
    @PutMapping
    @ApiOperation("修改套餐信息")
    public Result<String> update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐信息：{}", setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();

    }

    /**
     * 起售停售套餐
     * @param status  状态
     * @param id    套餐id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("起售停售套餐")
    public Result<String > startOrStop(@PathVariable("status") Long status ,@RequestParam("id") Long id){
        setmealService.startOrStop(status,id);
        return Result.success();


    }




}
